package com.hh.flow.service.impl;

import com.hh.flow.domain.FlowSkip;
import com.hh.flow.mapper.FlowSkipMapper;
import com.hh.flow.service.IFlowSkipService;
import com.hh.mybatis.service.impl.BaseServiceImpl;
import com.mybatisflex.core.query.QueryWrapper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

import static com.hh.flow.domain.tables.FlowSkipTableDef.flow_skip;

/**
 * 结点跳转关联Service业务层处理
 *
 * @author hh
 * @date 2023-03-29
 */
@Service
public class FlowSkipServiceImpl extends BaseServiceImpl<FlowSkip> implements IFlowSkipService {
    @Resource
    private FlowSkipMapper flowSkipMapper;

    @Override
    public FlowSkipMapper getBaseMapper() {
        return flowSkipMapper;
    }

    @Override
    public QueryWrapper buildWrapper(FlowSkip flowSkip) {
        QueryWrapper query = QueryWrapper.create()
                .where(flow_skip.definition_id.eq(flowSkip.getDefinitionId()))
                .and(flow_skip.node_id.eq(flowSkip.getNodeId()))
                .and(flow_skip.now_node_code.eq(flowSkip.getNowNodeCode()))
                .and(flow_skip.next_node_code.eq(flowSkip.getNextNodeCode()))
                .and(flow_skip.condition_value.eq(flowSkip.getConditionValue()));
        return query;
    }

    @Override
    public boolean deleteByNodeId(Long nodeId) {
        return remove(flow_skip.node_id.eq(nodeId));
    }

    /**
     * 根据nodeIds删除
     *
     * @param nodeIds 需要删除的nodeIds
     * @return 结果
     */
    @Override
    public boolean deleteByNodeIds(List<Long> nodeIds)
    {
        return remove(flow_skip.node_id.in(nodeIds));
    }

}
